home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / util / tai_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-04  |  2.0 KB  |  84 lines

  1. #include "util.h"
  2. #include <sys/stat.h>
  3.  
  4. /* Perform process start-up tailoring */
  5.  
  6. extern int errno;
  7.  
  8. char *tai_eptr;         /* point to error text, if any  */
  9.  
  10. LOCVAR char *tai_data;    /* pointer to incore copy of tai file */
  11. LOCVAR char *tai_ptr;   /* pointer to "next" tai record */
  12.  
  13. tai_init (filename)    /* prepare to get tailoring information */
  14.     char filename[]; /* location of the info */
  15. {
  16.     extern char *malloc ();
  17.     struct stat statbuf;
  18.     unsigned taisize; /* number of bytes in the tai file */
  19.     int fd;
  20.  
  21.     if (stat (filename, &statbuf) < OK)
  22.         return (NOTOK);     
  23.     taisize = (unsigned) st_gsize (&statbuf);
  24.     if ((tai_data = malloc (taisize + 1)) == 0)
  25.         return (NOTOK);
  26.     if ((fd = open (filename, 0)) < 0)
  27.         return (NOTOK);
  28.     if (read (fd, tai_data, taisize) != taisize)
  29.     {
  30.         (void) close (fd);
  31.         errno = EIO;    /* i/o error */
  32.         return (NOTOK);
  33.     }
  34.     tai_data[taisize] = '\0';
  35.     (void) close (fd);
  36.     tai_ptr = tai_data;
  37.     return (OK);
  38. }
  39.  
  40.  
  41. tai_end ()
  42. {
  43.     tai_data = 0;
  44.     return (OK);
  45. }
  46. /* */
  47.  
  48. tai_get (max, argv)    /* get next parsed tailoring line */
  49.     int max;    /* maximum number of allowable fields */
  50.     char *argv[];    /* array to hold pointers to field elements */
  51. {
  52.     int retval;
  53.     register char *nxtptr;             /* beginning of next record     */
  54.  
  55. retry:
  56.     if (tai_ptr == 0)
  57.         return (0);
  58.  
  59.     for (nxtptr = tai_ptr; *nxtptr != '\0'; nxtptr++)
  60.     if (*nxtptr == '\n')
  61.     {                       /* skip over to the next record */
  62.         *nxtptr = ' ';      /* no-op the newline            */
  63.         nxtptr++;
  64.         if (*nxtptr != ' ' && *nxtptr != '\t')
  65.         {                   /* continuation line            */
  66.         nxtptr[-1] = '\0';
  67.         break;
  68.         }
  69.     }
  70.  
  71.     retval = str2arg (tai_ptr, max, argv, (char *) 0);
  72.     if (retval < 0)
  73.     tai_eptr = tai_ptr;        /* record where the error happened   */
  74.     if (*nxtptr == '\0')
  75.     tai_ptr = 0;
  76.     else
  77.     tai_ptr = nxtptr;
  78.  
  79.     if (retval == 0)                /* nothing but comments on line */
  80.     goto retry;                 /* get something useful         */
  81.  
  82.     return (retval);
  83. }
  84.